<div ng-controller="Supplier_AddC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">贸易商添加</h1>
    </div>
    <div class="modal fade" id="dlg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">人员选择</h4>
                </div>
                <div class="modal-body">
                    <!--<input class="selectFind form-control" type="text" ng-model="searchTxt" placeholder="查找" />-->
                    <div class="input-group ">
                        <input class="selectFind form-control" type="search" ng-model="searchTxt" placeholder="查找">
                        <span class="glyphicon glyphicon-remove input-group-addon" ng-click="empty()"></span>
                    </div>
                    <div class="selectShow" style="width: 100%; height: 200px; border: 1px solid #CCCCCC; overflow: auto;">
                        <div style="cursor: pointer;" class="form-control" ng-click="selectEmp(x , 1)" ng-repeat=" x in userdata|filter:{Name : searchTxt}">{{x.Name}}</div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="dlg1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel1">人员选择</h4>
                </div>
                <div class="modal-body">
                    <!--<input class="selectFind form-control" type="text" ng-model="searchTxt" placeholder="查找" />-->
                    <div class="input-group ">
                        <input class="selectFind form-control" type="search" ng-model="searchTxt" placeholder="查找">
                        <span class="glyphicon glyphicon-remove input-group-addon" ng-click="empty()"></span>
                    </div>
                    <div class="selectShow" style="width: 100%; height: 200px; border: 1px solid #CCCCCC; overflow: auto;">
                        <div style="cursor: pointer;" class="form-control" ng-click="selectEmp(x , 2)" ng-repeat=" x in userdata|filter:{Name : searchTxt}">{{x.Name}}</div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                </div>
            </div>
        </div>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <!--<div class="form-group">-->
                                <!--<label>供应商类型</label>-->
                                <!--<select  ng-change="change1()" required class="form-control" ng-model="supplierdata.ProviderType">-->
                                    <!--&lt;!&ndash;<option value="0">钢厂</option>&ndash;&gt;-->
                                    <!--<option value="1">仓库</option>-->
                                    <!--<option value="2">贸易商</option>-->
                                <!--</select>-->
                            <!--</div>-->
                            <div class="form-group">
                                <label>贸易商名称</label>
                                <input ng-model="supplierdata.Name" type="text" class="form-control" required >
                            </div>
                            <div class="form-group">
                                <label>区域</label>
                                <div class="input-group ">
                                    <span class="input-group-addon">省</span>
                                    <select required class="form-control" ng-options="x.FillName for x in items" ng-model="selectedDistrict1"></select>
                                    <span class="input-group-addon">市</span>
                                    <select required class="form-control" ng-options="x as x.Name for x in selectedDistrict1.Children" ng-model="supplierdata.District"></select>
                                </div>
                            </div>
                            <div class="checkbox">
                                    <label for="feibiao" style="margin-right: 10px; padding: 0px">是否允许非标</label>
                                    <label class="i-checks">
                                        <input type="checkbox" id="feibiao" ng-model="supplierdata.IsNonStandard">
                                        <i></i>
                                    </label>
                                </div>
                            <div class="form-group">
                                <label>先款优惠</label>
                                <input ng-model="supplierdata.FullPaymentDiscount" type="number" min="0"  class="form-control" required>
                            </div>
                            <div class="form-group" ng-if="supplierdata.IsNonStandard">
                                <label>非标优惠</label>
                                <input ng-model="supplierdata.NonstandardDiscount" type="number" min="0" class="form-control" required>
                            </div>

                            <div class="form-group">
                                <label>区域经理</label>
                                <!--<select required class="form-control" ng-options="x.Name for x in userdata" ng-model="supplierdata.Manager"></select>-->
                                <button class="form-control text-left" ng-model="supplierdata.Manager.Name" data-toggle="modal" data-target="#dlg">
                                    {{supplierdata.Manager.Name}}
                                </button>
                            </div>
                            <div class="form-group">
                                <label>驻厂专员</label>
                                <!--<select required class="form-control" ng-options="x.Name for x in userdata" ng-model="supplierdata.MainFieldMan"></select>-->
                                <button class="form-control text-left" ng-model="supplierdata.MainFieldMan.Name" data-toggle="modal" data-target="#dlg1">
                                    {{supplierdata.MainFieldMan.Name}}
                                </button>
                            </div>
                            <div class="row text-right" style="text-align:center">
                                <button type="button" class="btn btn-success" ng-disabled="form.$invalid" ng-click="suppsub()">添加供应商</button>
                                <span style="padding:0 5%"></span>
                                <button type="button" class="btn btn-default" ng-click="$state.go('app.TraderManage_List')">取消</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
            .controller("Supplier_AddC", function ($scope, $state, $http,$stateParams) {
                $scope.selectedDistrict1 = "";
                $scope.supplierdata = {
                    ProviderType : 2
                };
                //获取地市
                $http({
                    url:"../api/District",
                    method:"GET"
                })
                        .then(function (res) {
                            $scope.items = res.data;
                        })
                        .then(function (error) {
                            if(error){
                                console.log("error");
                            }
                        });
                //获取人员
                $http({
                    url: "../api/Employee/List?name=&page=1&rows=9999",
                    method:"GET"
                })
                        .then(function (res) {
                            $scope.userdata = res.data.Data;
                        })
                        .then(function (error) {
                            if(error){
                                console.log("error");
                            }
                        });
//            提交信息
                $scope.suppsub = function(){
//                console.log($scope.supplierdata);
                    $http.post('../api/Provider', $scope.supplierdata)
                            .success(function (res) {
                                if (res.State <= 0) {
                                    alert(res.Msg);
                                } else {
                                    alert("添加成功");
                                    $state.go('app.TraderManage_List');
                                }
                            });
                };
                $scope.selectEmp= function(emp , type) {
                    if(type == 1){
                        $scope.supplierdata.Manager = emp;
                        console.log($scope.supplierdata.Manager);
                        $('#dlg').modal("hide");
                    }else if (type == 2){
                        $scope.supplierdata.MainFieldMan = emp;
                        console.log($scope.supplierdata.MainFieldMan);
                        $('#dlg1').modal("hide");
                    }

                };

            })

</script>